"""
transpose和permute都是交换张量的维度
    区别在于 transpose一次只能交换2个维度
            permute一次可以交换多个维度
语法：
    transpose：torch.transpose(data, m, n)     => 交换m和n的维度
    permute方式一：data.permute(2, 1, 0)        => 初始形状是0,1,2, 将2的和0交换, 1不变
    permute方式二：torch.permute(data, [2, 0, 1])   => 初始形状是0,1,2，转换成2，0，1
"""
import torch
import torch as t

data = t.randint(1, 100, [2, 3, 4])
print("================= 原始数据 =================")
print(data)
print(data.shape)

print("================= data交换维度0和1 =================")
data2 = t.transpose(data, 0, 1)
print(data2)
print(data2.shape)

print("================= data交换维度0和2 =================")
data2 = t.transpose(data, 0, 2)
print(data2)
print(data2.shape)

print("================= data交换维度0和2 2 =================")
data3 = t.transpose(data2, 0, 2)
print(data3)
print(data3.shape)

print("================= data permute交换维度 方式一 =================")
data4 = data.permute(2, 1, 0)
print(data4)
print(data4.shape)

print("================= data permute交换维度 方式二 =================")
data5 = torch.permute(data, [2, 0, 1])
print(data5)
print(data5.shape)
